import EnterpriSe from '@/components/EnterpriSe.vue'
import EnterpriseData from '@/components/EnterpriseData.vue'
import HelloWorld from '@/components/HelloWorld.vue'
import ManageMent from '@/components/ManageMent.vue'
import PermissIon from '@/components/PermissIon.vue'
import ProvincialData from '@/components/ProvincialData.vue'
import ServiceSata from '@/components/ServiceSata.vue'
import SiLing from '@/components/SiLing.vue'
import SubsiDiary from '@/components/SubsiDiary.vue'
import HomePage from '@/views/HomePage.vue'
import RegiSter from '@/views/RegiSter.vue'
import RegisTerS from '@/views/RegisTerS.vue'


import vue from 'vue'
import VueRouter from 'vue-router'
vue.use(VueRouter)


var routes = [{
  path:'/',
  redirect:'deng'
},{
    path:'/zhu',
    name:'zhu',
    component:RegiSter,
    meta:{title:'注册'}
  },{
    path:'/deng',
    name:'deng',
    component:RegisTerS,
    meta:{title:'登录'}
  },{
    path:'/shou',
    name:'shou',
    component:HomePage,
    meta:{is : true , title: '首页'},
    // 一层子路由
    children:[{
      path:'/',
      redirect:'shouy'
    },{
    path:'shouy',
    name:'shouy',
    component:HelloWorld,
    meta:{is : true , title: '首页'},
    // 二层子路由
    children:[{
       path:'/',
  redirect:'qysj'
    },{
      path:'qysj',
      name:'qysj',
      component:EnterpriseData,
      meta:{title:'企业数据'}
    },{
      path:'fwsj',
      name:'fwsj',
      component:ServiceSata,
      meta:{title:'服务数据'}
    },{
      path:'sfsj',
      name:'sfsj',
      component:ProvincialData,
      meta:{title : '省份数据'}
    }]
  },{
    path:'qiy',
    name:'qiy',
    component:EnterpriSe,
    meta:{title:'企业管理'},
    children:[{
      path:'/',
      redirect:'cjqygl'
    },{
      path:'cjqygl',
      name:'cjqygl',
      component:ManageMent,
       meta:{title:'超级企业管理'},
    },{
      path:'zqygl',
      name:'zqygl',
      component:SubsiDiary,
       meta:{title:'子企业管理'},
    }]
  },{
    path:'qxgl',
    name:'qxgl',
    component:PermissIon,
    meta:{title:'权限管理'}
  }]
  
  },{
    path:'*',
    component:SiLing,
    meta:{title: '404'},
  }] 



var router =  new VueRouter({
  routes
})
export default router


// 前置路由守卫
// 登录和注册信息一致才能进入首页
router.beforeEach((to,from,next) =>{
  // console.log(to,from,next);
  
  if(to.meta.is == true){
    if(localStorage.getItem('user') == localStorage.getItem('username') && localStorage.getItem('pwd') == localStorage.getItem('password')){
      next()
    }
  }else{
    next()
  }
})




router.afterEach((to) =>{
  document.title = to.meta.title
})